<template>
  <!-- 员工实名认证审核 -->
  <div class="staffCheck">
    <!-- 头部区域 -->
    <div class="header">
      <!-- 起止时间选择框 -->
      <el-date-picker
        v-model="StartAndEndTime"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right"
        style="width: 400px"
        value-format="timestamp"
      >
      </el-date-picker>

      <!-- 员工状态下拉框 -->
      <el-select
        v-model="staffStatus"
        clearable
        placeholder="请选择状态"
        style="width: 192px"
      >
        <el-option label="通过" value="通过"> </el-option>
        <el-option label="不通过" value="不通过"> </el-option>
        <el-option label="未审核" value="未审核"> </el-option>
      </el-select>

      <!-- 申请人编号输入框 -->
      <el-input
        placeholder="申请人编号"
        v-model="staffNumber"
        clearable
        style="width: 192px"
      >
      </el-input>

      <!-- 查询按钮 -->
      <el-button type="primary" style="width: 100px" @click="queryStaff()"
        >查询</el-button
      >
    </div>
    <!-- 表格区域 -->
    <el-table :data="staffData" style="width: 100%">
      <el-table-column type="index" label="序号" align="center">
      </el-table-column>
      <el-table-column prop="userId" label="申请人编号" align="center">
      </el-table-column>
      <el-table-column prop="realname" label="姓名" align="center">
      </el-table-column>
      <el-table-column
        prop="applyTime"
        label="申请时间"
        align="center"
        :formatter="dateFormat"
      >
      </el-table-column>
      <el-table-column prop="idCard" label="身份证号" align="center">
      </el-table-column>
      <el-table-column label="身份证正面" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            src="http://bpic.588ku.com/element_origin_min_pic/18/06/10/d94f9766a82e40b2c96ddd359c6a59d7.jpg"
            :preview-src-list="[scope.row.idcardPhotoPositive]"
            v-if="!scope.row.idcardPhotoPositive"
          >
          </el-image>

          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.idcardPhotoPositive"
            :preview-src-list="[scope.row.idcardPhotoPositive]"
            v-else
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="身份证反面" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.idcardPhotoNegative"
            :preview-src-list="[scope.row.idcardPhotoNegative]"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="bankCard" label="银行卡卡号" align="center">
      </el-table-column>
      <el-table-column label="银行卡" align="center">
        <template slot-scope="scope">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.bankCardPhoto"
            :preview-src-list="[scope.row.bankCardPhoto]"
          >
          </el-image>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.status == '不通过'"
            >不通过</el-tag
          >
          <el-tag type="danger" v-else>通过</el-tag>
        </template>
      </el-table-column>
    </el-table>
    <!-- 底部分页 -->
    <div class="paginetion">
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[2, 4, 6, 8]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { get } from "@/utils/request";
import moment from "moment";
export default {
  data() {
    return {
      // 页面展示的总条数
      total: 0,

      // 分页大小
      pageSize: 8,

      // 当前页码
      currentPage: 1,

      // 日期快捷选项参数
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },

      // 起止日期 [new Date(2000, 10, 10, 10, 10), new Date(2000, 10, 11, 10, 10)]
      StartAndEndTime: "",

      // 员工状态
      staffStatus: "",

      // 申请人编号
      staffNumber: "",

      // 员工表格数据
      staffData: [],

      // 员工查询数据
      queryData: [],
    };
  },
  computed: {},
  methods: {
    // 时间戳格式化
    dateFormat(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    // 查询干员
    queryStaff() {
      let data = null;
      if (!this.StartAndEndTime) {
        data = {
          status: this.staffStatus,
          userId: this.staffNumber,
        };
      } else {
        data = {
          status: this.staffStatus,
          userId: this.staffNumber,
          beginTime: this.StartAndEndTime[0],
          endTime: this.StartAndEndTime[1],
        };
      }

      for (const key in data) {
        if (!data[key]) {
          delete data[key];
        }
      }
      this.page = 1;
      this.queryData = data;
      this.queryStaffData();
    },

    // 请求干员数据
    async queryStaffData() {
      const data = {
        page: this.currentPage,
        pageSize: this.pageSize,
      };
      const res = await get("/certification/pageQueryCertificationApply", {
         ...data,
        ...this.queryData,
      });
      this.staffData = res.data.list;
      this.total = res.data.total;
    },

    // 控制每页展示几条
    // val是条目数
    handleSizeChange(val) {
      this.pageSize = val;
      queryStaffData();
    },

    // 控制显示的页数
    // val控制页码
    handleCurrentChange(val) {
      this.currentPage = val;
      this.queryStaffData();
    },
  },
  created() {
    this.queryStaffData();
  },
  mounted() {},
};
</script>
<style scoped>
.header {
  line-height: 28px;
}
.paginetion {
  position: absolute;
  right: 20px;
  bottom: 10px;
}
</style>